<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class AddColumnParentIdInCategoryTable extends AbstractMigration
{
    public function up()
    {
        $this->table('category')
            ->addColumn('parent_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '父级ID'])
            ->addColumn('sort_index', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '排序id'])
            ->addIndex(['parent_id'], ['name' => 'idx_parent', 'type' => 'normal'])
            ->save();
    }

    public function down()
    {
        $this->table('category')
            ->removeColumn('parent_id')
            ->removeColumn('sort_index')
            ->removeIndexByName('idx_parent')
            ->save();
    }
}
